using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Web;
using iPhOwa.Exchange.ContentClasses;
using iPhOwa.Exchange.Managers;

namespace iPhOwa.Web
{
	public partial class ViewAppointment : iPhOwaPage
	{
		/// <summary>
		/// Page load event.
		/// </summary>
		[SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")]
		protected void Page_Load(object sender, EventArgs e)
		{
			string path = Request["path"];

			Appointment appointment = AppointmentManager.Get(new Uri(path), OwaSession);

			if(appointment == null)
			{
				throw new ApplicationException("No appointment found!");
			}

			if(appointment.ParentName != null)
			{
				Folder parentFolder = FolderManager.Get(appointment.ParentName, OwaSession);

				if(parentFolder != null)
				{
					parentNameLabel.Text = parentFolder.DisplayName;
					backPanel.Visible = true;

					// TODO: This should to a basic folder page that determines the folder type...
					backPanel.Href = string.Format(CultureInfo.InvariantCulture, "ViewFolder.aspx?path={0}", parentFolder.Href);
				}
			}

			Title = string.Format(CultureInfo.CurrentUICulture, "{0} - iPhOwa", appointment.NormalizedSubject);

			fromLabel.Text = appointment.DisplayStartDateTime;
			toLabel.Text = appointment.DisplayEndDateTime;
			subjectLabel.Text = appointment.NormalizedSubject;
			locationLabel.Text = appointment.Location;
			bodyLabel.Text = HttpUtility.HtmlDecode(appointment.HtmlDescription);
		}
	}
}